package com.leapp.sk.util

import android.app.Activity
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.example.baselibrary.R
import com.example.mvp.view.WindowBottomDialog


/**
 * 分享Dialog
 * @author  chaohaipeng  on 2018/8/4.
 */
class ShareDialogUtils {
    private object mHolder {
        val instance = ShareDialogUtils()
    }

    companion object {
        fun getInstance(): ShareDialogUtils {
            return mHolder.instance
        }
    }

    /**
     * 底部弹出Dialog
     */
    private var windowBottomDialog: WindowBottomDialog? = null
    /**
     * 上下文
     */
    private var mActivity: Activity? = null

    /**
     * 分享
     * @param activity activity
     * @param content 分享的内容
     * @param listener 监听
     */
    fun initSharedDialog(activity: Activity, content: String, listener: SharedListener,isVisibleDelete:Boolean) {
        mActivity = activity
        windowBottomDialog = WindowBottomDialog(activity, 0)
        val bottomView = View.inflate(activity, R.layout.layout_dialog_share, null)
        val ll_lds_qq = bottomView.findViewById<LinearLayout>(R.id.ll_lds_qq)
        val ll_lds_wx = bottomView.findViewById<LinearLayout>(R.id.ll_lds_wx)
        val ll_lds_wxfriend = bottomView.findViewById<LinearLayout>(R.id.ll_lds_wxfriend)
        val ll_lds_down = bottomView.findViewById<LinearLayout>(R.id.ll_lds_down)
        val tv_lds_cancle = bottomView.findViewById<TextView>(R.id.tv_lds_cancle)
        val ll_lds_delste = bottomView.findViewById<LinearLayout>(R.id.ll_lds_delste)
        val ll_lds_delete_image = bottomView.findViewById<LinearLayout>(R.id.ll_lds_delete_image)

          if (isVisibleDelete){
              ll_lds_delste.visibility=View.VISIBLE
          }else{
              ll_lds_delste.visibility=View.GONE
          }



        windowBottomDialog?.setBottomView(bottomView)
        ll_lds_qq.setOnClickListener(View.OnClickListener {
            listener.sharedToQQFriend(content)
            windowBottomDialog?.dismiss()

        })

        ll_lds_wx.setOnClickListener(View.OnClickListener {
            listener.sharedToWXFriend(content)
            windowBottomDialog?.dismiss()

        })
        ll_lds_wxfriend.setOnClickListener(View.OnClickListener {
            listener.sharedToWXFriendCircle(content)
            windowBottomDialog?.dismiss()

        })

        ll_lds_down.setOnClickListener(View.OnClickListener {
            listener.downLoad(content)
            windowBottomDialog?.dismiss()
        })
        ll_lds_delete_image.setOnClickListener(View.OnClickListener {
            listener.deleteImage(content)
            windowBottomDialog?.dismiss()

        })
        tv_lds_cancle.setOnClickListener(View.OnClickListener {
            windowBottomDialog?.dismiss()

        })


    }

    /**
     * 打开dialog
     */
    fun showDialog() {
        val finishing = mActivity?.isFinishing
        val showing = windowBottomDialog?.isShowing
        if (finishing != null && showing != null) {
            if (!finishing && !showing) {
                windowBottomDialog?.show()
            }
        }


    }

    interface SharedListener {

        fun sharedToWXFriend(content: String)

        fun sharedToWXFriendCircle(content: String)

        fun sharedToQQFriend(content: String)

        fun downLoad(content: String)
        fun deleteImage(content: String)
    }


}